package o;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.R;
import com.huawei.appmarket.service.globe.bean.UserAuthResponse;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import BaseDialog.a;
import o.dio.c;

public class dzx extends dzr<Void, Void> implements AccountBussinessListener, eqn {
    private static long ˎ = 0;
    private static long ॱ = 0;
    private long ʼ = 0;
    private long ˊ = 0;
    private Activity ˋ;
    private String ˏ = "";

    class b extends dow {
        private boolean ˊ = false;
        final /* synthetic */ dzx ˋ;

        public b(dzx o_dzx, boolean z) {
            this.ˋ = o_dzx;
            this.ˊ = z;
        }

        public void ˋ(boolean z, ccm o_ccm) {
            Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow onHwIDResult fromUserAuth=" + this.ˊ);
            if (z) {
                dzl.ˏ("login", this.ˋ.ˊ);
                String ॱ = eqp.ॱ();
                if (!dof.ˋ(ॱ)) {
                    boolean z2 = !ॱ.equalsIgnoreCase(this.ˋ.ˏ);
                    Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow onHwIDResult homeCountryChanged: " + z2 + " - " + ॱ);
                    if (z2) {
                        this.ˋ.ॱᐝ();
                        dte.ˋ(true);
                        return;
                    }
                }
            }
            if (z && this.ˋ.ˊ()) {
                Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow setSignedForUser true.");
                ccx.ˏ(this.ˋ.ˏ, true);
            }
            if (this.ˊ) {
                if (z) {
                    eqm ˊ = eqk.ˊ();
                    if (ˊ == null) {
                        dzl.ˋ("208", "ProcesserNull");
                        Logger.e("GLOBAL_START_FLOW", "LoginFlow grsProcesser is null.");
                        this.ˋ.ˏ();
                        return;
                    }
                    dzx.ˎ = dgh.ॱ();
                    ˊ.ॱ(new e(this.ˋ, this.ˋ.ˋ));
                    dte.ˋ(true);
                }
            } else if (z) {
                this.ˋ.ʼ = dgh.ॱ();
                dte.ˋ(true);
            }
        }

        public ccr ˏ() {
            ccr ˏ = super.ˏ();
            ˏ.ˏ(true);
            if (this.ˊ) {
                ˏ.ˋ(false);
            }
            return ˏ;
        }
    }

    static class d implements IServerCallBack {
        private SoftReference<dzx> ॱ;

        public d(dzx o_dzx) {
            this.ॱ = new SoftReference(o_dzx);
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            dzx o_dzx;
            if ((responseBean instanceof UserAuthResponse) && responseBean.getResponseCode() == 0) {
                UserAuthResponse userAuthResponse = (UserAuthResponse) responseBean;
                if (userAuthResponse.getRtnCode_() == 0 || userAuthResponse.getRtnCode_() == 2) {
                    dzl.ˏ("userAuth", dzx.ॱ);
                    Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow response from store getHomeCountry_()= " + userAuthResponse.ˏ());
                    UserSession.getInstance().setHomeCountry(userAuthResponse.ˏ());
                    eop.ˎ(UserSession.getInstance());
                    o_dzx = (dzx) this.ॱ.get();
                    if (o_dzx != null) {
                        o_dzx.ͺ();
                        return;
                    }
                    return;
                }
                o_dzx = (dzx) this.ॱ.get();
                if (o_dzx != null) {
                    o_dzx.ˊॱ();
                    return;
                }
                return;
            }
            o_dzx = (dzx) this.ॱ.get();
            if (o_dzx != null) {
                o_dzx.ˊॱ();
            }
        }
    }

    static class e implements eql {
        private WeakReference<Activity> ˊ;
        private SoftReference<dzx> ˋ;

        public e(dzx o_dzx, Activity activity) {
            this.ˋ = new SoftReference(o_dzx);
            this.ˊ = new WeakReference(activity);
        }

        public void ˋ() {
            Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow GrsProcesser onSuccess start UserAuthRequest");
            dzl.ˏ("grs", dzx.ˎ);
            if (this.ˋ.get() != null) {
                dzx.ॱ = dgh.ॱ();
                cvt o_dzq = new dzq();
                if (this.ˊ != null) {
                    o_dzq.setServiceType_(dgm.ˎ((Activity) this.ˊ.get()));
                }
                if (eos.ˊ() != null) {
                    o_dzq.ˎ(eos.ˏ());
                    cfw.ˎ(o_dzq, new d((dzx) this.ˋ.get()));
                }
            }
        }

        public void ˎ(int i) {
            Logger.ˋ("GLOBAL_START_FLOW", "LoginFlow GrsProcesser onFailed code=" + i);
            eok.ˎ().ॱ(20, i, "Failed to access GRS server.");
            dzx o_dzx = null;
            if (this.ˋ.get() != null) {
                o_dzx = (dzx) this.ˋ.get();
            }
            if (o_dzx != null) {
                o_dzx.ˏ();
            }
        }
    }

    protected /* synthetic */ void ˊ(Object obj) {
        ˎ((Void) obj);
    }

    protected /* synthetic */ Object ˎ(Object obj) {
        return ॱ((Void) obj);
    }

    public dzx(Activity activity, boolean z) {
        super(z);
        this.ˋ = activity;
    }

    protected String ॱ() {
        return "LoginFlow";
    }

    protected Void ॱ(Void voidR) {
        Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow process");
        if (doo.ˊ(ContentManager.getInstant().getContext())) {
            ˎ();
            this.ˏ = eqp.ॱ();
            if (UserSession.getInstance().isLoginSuccessful()) {
                if (ˊ()) {
                    Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow setSignedForUser And reportSignResult true.");
                    ccx.ˏ(this.ˏ, true);
                    ccx.ˎ(true, null);
                }
                ͺ();
            } else if (dof.ˋ(eqp.ॱ())) {
                ˊॱ();
            } else {
                ˏॱ();
            }
        } else {
            Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow not has network");
            dzl.ˋ("205", "NETWORK-UNCONNECTED");
            ˏ();
        }
        return null;
    }

    private void ˊॱ() {
        eoj.ˋ().ˎ("LoginFlow", this);
        eqq.ˋ().ˎ("LoginFlow", this);
        Context ˋ = ContentManager.getInstant().getContext();
        ccw bVar = new b(this, false);
        this.ˊ = dgh.ॱ();
        eod.ˊ(ˋ, bVar, true, true, true);
    }

    private void ˏॱ() {
        eoj.ˋ().ˎ("LoginFlow", this);
        Context ˋ = ContentManager.getInstant().getContext();
        ccw bVar = new b(this, true);
        this.ˊ = dgh.ॱ();
        eod.ˊ(ˋ, bVar, true, false, true);
    }

    public void onResult(int i) {
        Logger.ˎ("GLOBAL_START_FLOW", "LoginFlowonResult " + i);
        if (i == 202 || i == 201) {
            dzl.ˏ("getUserInfo", this.ʼ);
            ͺ();
        } else if (i == 203) {
            dzl.ˋ("210", "code=" + i);
            ʻॱ();
        }
    }

    private void ͺ() {
        boolean z = false;
        String ॱ = eqp.ॱ();
        if (dof.ˋ(ॱ)) {
            dzl.ˋ("204", "goNextAfterAuthSucc");
            Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow UserInfoHandler onFinish homeCountry is blank");
            evk.ॱ(ContentManager.getInstant().getContext().getString(R.string.connect_server_fail_prompt_toast), 0).ˋ();
            ˏ();
            return;
        }
        if (!ॱ.equalsIgnoreCase(this.ˏ)) {
            z = true;
        }
        Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow homeCountryChanged: " + z + " - " + ॱ);
        if (z) {
            ॱᐝ();
        } else if (dzv.ˋ()) {
            ˎ(null);
        } else {
            nextFlow(new dzs(this.ˋ, ˊ()));
            ˎ(null);
        }
    }

    public void onAccountBusinessResult(ccp o_ccp) {
        Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow onAccountBusinessResult accountResult=" + o_ccp);
        if (DialogButton.CONFIRM != o_ccp.ˎ) {
            return;
        }
        if (10104 == o_ccp.ˋ || 10105 == o_ccp.ˋ) {
            if (10104 == o_ccp.ˋ) {
                dzl.ˋ("200", "10104");
            } else if (10105 == o_ccp.ˋ) {
                dzl.ˋ("201", "10105");
            }
            Logger.ˋ("LoginFlow", "ACCOUNT_ERROR_HWID_NOT_EXISIT");
            ˋ();
        } else if (10102 == o_ccp.ˋ) {
            dzl.ˋ("202", "10105");
            ˋ();
        } else if (10103 == o_ccp.ˋ) {
            dzl.ˋ("211", "10105");
            ʻॱ();
        } else {
            Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow ACCOUNT_LOGIN_FAILED");
            ʻॱ();
        }
    }

    private String ॱˎ() {
        String ˏ = eos.ˏ();
        if (TextUtils.isEmpty(ˏ)) {
            ˏ = UserSession.getInstance().getHomeCountry();
        }
        Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow getFromCache homeCountry=" + ˏ);
        return ˏ;
    }

    private void ʻॱ() {
        Object ॱˎ = ॱˎ();
        if (TextUtils.isEmpty(ॱˎ)) {
            Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow setRetryFlag=true.");
            dzp.ˏ().ˏ(true);
            dzr o_dzs = new dzs(this.ˋ, ˊ());
            o_dzs.ˋ(true);
            nextFlow(o_dzs);
            dzl.ˋ("204", "goNextFlowByCache");
            ˎ(null);
            return;
        }
        UserSession.getInstance().setHomeCountry(ॱˎ);
        eop.ˎ(UserSession.getInstance());
        nextFlow(new dzs(this.ˋ, ˊ()));
        ˎ(null);
    }

    private void ॱᐝ() {
        Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow showChangDlg");
        this.ˏ = eqp.ॱ();
        if (Looper.myLooper() != Looper.getMainLooper()) {
            new Handler(Looper.getMainLooper()).post(new Runnable(this) {
                final /* synthetic */ dzx ˎ;

                {
                    this.ˎ = r1;
                }

                public void run() {
                    this.ˎ.ॱᐝ();
                }
            });
            return;
        }
        ॱˋ();
        dgh.ˏ();
        diu.ˊ().ॱ();
        ((bod) bkt.ˋ("DynamicCore", bod.class)).ˎ();
        egv.ॱᐝ().ˏॱ();
        dhq.ॱ().ˊ();
        euf.ˎ().ॱॱ();
        dvt.ˏ().ˋ(1);
        ekg.ॱ().ˏ();
        egn.ˎ().ॱ();
        eec.ˊ().ˏ();
        String ˊ = eqp.ˊ();
        BaseAlertDialog ˋ = BaseAlertDialog.ˋ(this.ˋ, null, this.ˋ.getString(R.string.hispace_global_protocol_switch_new, new Object[]{ˊ}));
        ˋ.ˏ(a.CANCEL, 8);
        ˋ.ॱ();
        ˋ.ˎ(new OnDismissListener(this) {
            final /* synthetic */ dzx ˏ;

            {
                this.ˏ = r1;
            }

            public void onDismiss(DialogInterface dialogInterface) {
                this.ˏ.ˈ();
            }
        });
        ˋ.ॱ(a.CONFIRM, (int) R.string.exit_confirm);
        ˋ.ˎ(false);
    }

    private void ॱˋ() {
        if (this.ˋ.getRequestedOrientation() == -1) {
            try {
                this.ˋ.setRequestedOrientation(ᐝॱ());
            } catch (Throwable e) {
                Logger.ˋ("GLOBAL_START_FLOW", "LoginFlow Exception.", e);
            }
        }
    }

    private int ᐝॱ() {
        int i = this.ˋ.getResources().getConfiguration().orientation;
        if (1 == i) {
            return 1;
        }
        return 2 == i ? 0 : -1;
    }

    private void ʾ() {
        cvt.setApsid_(System.currentTimeMillis());
        nextFlow(new dzs(this.ˋ, ˊ()));
        ˎ(null);
    }

    private void ˈ() {
        diu.ˊ().ॱ(this.ˋ, new c(this) {
            final /* synthetic */ dzx ˏ;

            {
                this.ˏ = r1;
            }

            public void ॱ(boolean z) {
                Logger.ˎ("LoginFlow", "ProtocolComponent.showProtocol agreeResult, isAgree: " + z);
                if (z) {
                    Logger.ˎ("GLOBAL_START_FLOW", this.ˏ.ॱ() + " setSignedOnStartup true.");
                    this.ˏ.ˎ(true);
                    Logger.ˎ("GLOBAL_START_FLOW", "LoginFlow setSignedForUser true.");
                    ccx.ˏ(this.ˏ.ˏ, true);
                    this.ˏ.ʾ();
                    return;
                }
                dzl.ˋ("203", "CANCEL-PROTOCOL");
                this.ˏ.ˋ();
            }
        });
    }

    protected void ˎ(Void voidR) {
        eoj.ˋ().ˊ("LoginFlow");
        eqq.ˋ().ˊ("LoginFlow");
        super.ˊ((Object) voidR);
    }

    protected void ˏ() {
        eoj.ˋ().ˊ("LoginFlow");
        eqq.ˋ().ˊ("LoginFlow");
        super.ˏ();
    }

    protected void ˋ() {
        eoj.ˋ().ˊ("LoginFlow");
        eqq.ˋ().ˊ("LoginFlow");
        super.ˋ();
    }
}
